package com.maidou.qiantai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.maidou.qiantai.vo.member.MemberAddressVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.maidou.qiantai.domain.MemberAddress;
import com.maidou.qiantai.service.IMemberAddressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收货地址Controller
 * 
 * @author maidou
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/qiantai/member/address")
public class MemberAddressController extends BaseController
{
    @Autowired
    private IMemberAddressService memberAddressService;

    /**
     * 查询收货地址列表
     */
    @GetMapping("/list")
    public TableDataInfo list()
    {
        startPage();
        List<MemberAddressVo> list = memberAddressService.selectMemberAddressVoList();
        return getDataTable(list);
    }

    /**
     * 查询收货地址列表
     */
//    @GetMapping("/list")
//    public TableDataInfo list()
//    {
//        startPage();
//        List<MemberAddressVo> list = memberAddressService.selectMemberAddressVoList();
//        return getDataTable(list);
//    }

    /**
     * 新增收货地址
     */
    @PostMapping("/add-address")
    public AjaxResult addAddress(@RequestBody MemberAddressVo memberAddressVo)
    {
        return toAjax(memberAddressService.insertMemberAddressVo(memberAddressVo));
    }

    /**
     * 修改收货地址
     */
    @PostMapping("/edit-address")
    public AjaxResult editAddress(@RequestBody MemberAddressVo memberAddressVo)
    {
        return toAjax(memberAddressService.updateMemberAddressVo(memberAddressVo));
    }

    /**
     * 修改收货地址
     */
    @GetMapping("/delete-address/{addressId}")
    public AjaxResult deleteAddress(@PathVariable("addressId") Long addressId)
    {
        return toAjax(memberAddressService.deleteMemberAddressById(addressId));
    }

    /**
     * 导出收货地址列表
     */
    @PreAuthorize("@ss.hasPermi('qiantai:address:export')")
    @Log(title = "收货地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberAddress memberAddress)
    {
        List<MemberAddress> list = memberAddressService.selectMemberAddressList(memberAddress);
        ExcelUtil<MemberAddress> util = new ExcelUtil<MemberAddress>(MemberAddress.class);
        util.exportExcel(response, list, "收货地址数据");
    }

    /**
     * 获取收货地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('qiantai:address:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(memberAddressService.selectMemberAddressById(id));
    }

    /**
     * 新增收货地址
     */
    @PreAuthorize("@ss.hasPermi('qiantai:address:add')")
    @Log(title = "收货地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberAddress memberAddress)
    {
        return toAjax(memberAddressService.insertMemberAddress(memberAddress));
    }

    /**
     * 修改收货地址
     */
    @PreAuthorize("@ss.hasPermi('qiantai:address:edit')")
    @Log(title = "收货地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberAddress memberAddress)
    {
        return toAjax(memberAddressService.updateMemberAddress(memberAddress));
    }

    /**
     * 删除收货地址
     */
    @PreAuthorize("@ss.hasPermi('qiantai:address:remove')")
    @Log(title = "收货地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memberAddressService.deleteMemberAddressByIds(ids));
    }
}
